import {session} from "electron";
const api_v1=`https://access.v.qq.com/trpc.creator_center.entrance.Entrance/GetAccountInfo`
export const handleRequestApi = (webview:string) => {
  const webviewSession = session.fromPartition("persist:"+webview);
  webviewSession.webRequest.onCompleted(async (details) => {
      // let api_v2=`https://nodeyun.video.qq.com/x/api/edit_profile/profile`
      if (details.url.includes(api_v1)) {
          console.log('Request Id:', details.id)
          console.log('Request URL:', details.url);
          console.log('Request Method:', details.method);
          console.log('Status Code:', details.statusCode);
          const cookies = await webviewSession.cookies.get({});
          const cookieHeader = cookies.map(cookie => `${cookie.name}=${cookie.value}`).join('; ');

          fetch(details.url, {
              method: details.method,
              headers: {
                  'Content-Type': 'application/json',
                  'Cookie': cookieHeader,
              }
          }).then(async resp => {
              const text =await resp.text();
              if (text) {
                  console.log('Response Body:', JSON.parse(text));
              }
          }).catch(err=>{
              console.log(err)
          })
      }
  })
}